package com.example.media;


import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import androidx.appcompat.app.AppCompatActivity;

import java.io.File;

public class Media extends AppCompatActivity {
    String path;
    VideoView video;
    MediaController mediaController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.activity_media);

        Intent intent = getIntent();
        path = intent.getStringExtra("path");
        File file = new File(path);

        video = (VideoView)findViewById(R.id.video);
        mediaController = new MediaController(this);

        if(file.exists()){
            video.setVideoPath(file.getAbsolutePath());
            video.setMediaController(mediaController);
            mediaController.setMediaPlayer(video);
            video.requestFocus();
        }
        else{
            Toast.makeText(Media.this,"视频不存在",Toast.LENGTH_LONG).show();
        }
    }
}
